/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/05
*/
#include "LuaBase.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

namespace LuaBase{

void RegisterLuaBaseAll(LuaState *L)
{
    LuaObject ns = L->GetGlobal("EDUI");
}

LuaObject ToLuaObj(LuaState *L, const Point *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetInteger("x", data->x);
    obj.SetInteger("y", data->y);

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const PointF *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetNumber("x", data->x);
    obj.SetNumber("y", data->y);

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const Size *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetInteger("w", data->w);
    obj.SetInteger("h", data->h);

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const Rect *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetInteger("x", data->x);
    obj.SetInteger("y", data->y);
    obj.SetInteger("w", data->w);
    obj.SetInteger("h", data->h);

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const Rect1 *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetInteger("l", data->l);
    obj.SetInteger("t", data->t);
    obj.SetInteger("r", data->r);
    obj.SetInteger("b", data->b);

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const Color *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetInteger("r", data->r);
    obj.SetInteger("g", data->g);
    obj.SetInteger("b", data->b);
    obj.SetInteger("a", data->a);
    obj.SetInteger("value", data->Value());

    return obj;
}

LuaObject ToLuaObj(LuaState *L, const ImageData *data)
{
    LuaObject obj;
    obj.AssignNil(L);
    if (!data) return obj;
    obj.AssignNewTable(L);

    obj.SetString("img", data->img.GetString());
    obj.SetString("mask", data->mask.GetString());
    obj.SetObject("src", ToLuaObj(L, data->src));
    obj.SetObject("dst", ToLuaObj(L, data->dst));
    obj.SetObject("cor", ToLuaObj(L, data->cor));
    obj.SetBoolean("hole", data->hole);
    obj.SetBoolean("center", data->center);

    return obj;
}

//AlignType to string
LuaObject ToLuaObj(LuaState *L, AlignType data)
{
    LuaObject obj;
    obj.AssignNil(L);

    switch (data){
        case ALIGN_CENTER:      obj.AssignString(L, "center"); break;
        case ALIGN_LEFT:        obj.AssignString(L, "left"); break;
        case ALIGN_LEFTTOP:     obj.AssignString(L, "lefttop"); break;
        case ALIGN_TOP:         obj.AssignString(L, "top"); break;
        case ALIGN_RIGHTTOP:    obj.AssignString(L, "righttop"); break;
        case ALIGN_RIGHT:       obj.AssignString(L, "right"); break;
        case ALIGN_RIGHTBOTTOM: obj.AssignString(L, "rightbottom"); break;
        case ALIGN_BOTTOM:      obj.AssignString(L, "bottom"); break;
        case ALIGN_LEFTBOTTOM:  obj.AssignString(L, "leftbottom"); break;
    }

    return obj;
}

//WndFullScreen to string
LuaObject ToLuaObj(LuaState *L, WndFullScreen data)
{
    LuaObject obj;
    obj.AssignNil(L);

    switch (data){
        case WND_FULLSCREEN_WINDOWED: obj.AssignString(L, "windowed"); break;
        case WND_FULLSCREEN_REAL:     obj.AssignString(L, "real"); break;
        case WND_FULLSCREEN_DESKTOP:  obj.AssignString(L, "desktop"); break;
    }

    return obj;
}

}
EDUI_NAMESPACE_END

#endif